/**
 * MineAdmin is committed to providing solutions for quickly building web applications
 * Please view the LICENSE file that was distributed with this source code,
 * For the full copyright and license information.
 * Thank you very much for using MineAdmin.
 *
 * @Author X.Mo<root@imoi.cn>
 * @Link   https://github.com/mineadmin
 */
import type { MaFormItem } from '@mineadmin/form'
import hasAuth from '@/utils/permission/hasAuth.ts'
import MaDictSelect from '@/components/ma-dict-picker/ma-dict-select.vue'
import MaDictRadio from '@/components/ma-dict-picker/ma-dict-radio.vue'
import MaRemoteSelect from '@/components/ma-remote-select/index.vue'
import { concat } from 'lodash-es'
import { rdOrganizeAreaStatusDictData }  from './common.tsx'
import { page as getProjLineList } from '@/plugins/ai-warning/organization/api/rdOrganizeProjLine.ts'


export default function getFormItems(formType: 'add' | 'edit' = 'add', t: any, model: any): MaFormItem[] {

  return concat([
    { 
      label: '所属项目线', 
      prop: 'proj_line_id', 
      render: () => MaRemoteSelect, 
      renderProps: { 
        api: getProjLineList,
        axiosConfig: {
          autoRequest: true,
          params: {
            page: 1,
            pageSize: 1000,
          }
        },
        dataHandle: (response: any) => {
          if (response.code === 200 && response.data && response.data.list) {
            return response.data.list.map((projLine: any) => ({
              label: projLine.name,
              value: projLine.id,
            }));
          }
          return [];
        },
        placeholder: t('form.pleaseSelect', { msg: '所属项目线' }),
        filterable: true,
        clearable: true,
      }, 
      itemProps: { 
        rules: [{ required: true, message: '请选择所属项目线' }] 
      } 
    },
    { 
      label: '工区名称', 
      prop: 'name', 
      render: 'input', 
      renderProps: { 
        placeholder: t('form.pleaseInput', { msg: '工区名称' }) 
      }, 
      itemProps: { 
        rules: [{ required: true, message: '请输入工区名称' }] 
      } 
    },
    { 
      label: '缩写', 
      prop: 'abbr', 
      render: 'input', 
      renderProps: { 
        placeholder: t('form.pleaseInput', { msg: '缩写' }) 
      } 
    },
    { 
      label: '工区地址', 
      prop: 'addr', 
      render: 'input', 
      renderProps: { 
        placeholder: t('form.pleaseInput', { msg: '工区地址' }) 
      } 
    },
    { 
      label: '经度', 
      prop: 'lat', 
      render: 'input', 
      renderProps: { 
        placeholder: t('form.pleaseInput', { msg: '经度' }),
        type: 'number'
      } 
    },
    { 
      label: '纬度', 
      prop: 'lng', 
      render: 'input', 
      renderProps: { 
        placeholder: t('form.pleaseInput', { msg: '纬度' }),
        type: 'number'
      } 
    },
    { 
      label: '排序', 
      prop: 'sort', 
      render: 'input', 
      renderProps: { 
        placeholder: t('form.pleaseInput', { msg: '排序' }) 
      } 
    },
    { 
      label: '状态', 
      prop: 'status', 
      render: () => MaDictRadio, 
      renderProps: { 
        multiple: false, 
        data: rdOrganizeAreaStatusDictData() 
      }, 
      itemProps: { 
        rules: [{ required: true, message: '请选择状态' }] 
      }
    },
    { 
      label: '备注', 
      prop: 'remark', 
      render: 'input', 
      renderProps: { 
        type: 'textarea',
        rows: 3,
        placeholder: t('form.pleaseInput', { msg: '备注' }) 
      } 
    },
    { 
      label: '摘要', 
      prop: 'abstract', 
      render: 'input', 
      renderProps: { 
        type: 'textarea',
        rows: 3,
        placeholder: t('form.pleaseInput', { msg: '摘要' }) 
      } 
    },
  ]);
}
